Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revised native conda locator #23416

Merged
merged 5 commits into from
May 13, 2024
Merged

Revised native conda locator #23416

merged 5 commits into from
May 13, 2024

Conversation

DonJayamanne
Copy link

@DonJayamanne DonJayamanne commented May 13, 2024

Fixes

  • Avoid spawning Conda to get list of environments and conda version #23413

  • & the fact that we always use the same conda exe to manage all conda envs, even if multiple are installed.

  • Step 1:

    • Look for conda install folders in known locations such as /<user home>/miniconda3, <user profile>/Anaconda3
  • Step 2:

    • For each install location identified, inspect that folder and extract the
      • Conda executable
      • All environments belonging to that conda installation
  • Step 3:

    • Old approach,
      1. find any conda in sys path or other locations and find conda installation via that mechanism
      1. Get all envs from environments.txt file (any remaining conda envs not discovered in 1 & 2 will be discoverred here and use some the global conda exe)
        Once we have step 1 and 2, I do not expect anything new to show up in step 3,
        Even if users install conda into some custom locations (the solution would be to run step 1 with the custom location provided by user in settings.json file)

How to find environments?

  • Look in the envs folder of the conda installation
  • Look at the entries in the environments.txt file
  • Look at the env_dirs in the .condarc file

With these two, we should be able to eliminate the need to ever spawn conda to get the env directories.

How do we know whether a conda environment belongs to a specific conda installation

  • If it is in the envs sub directory of the conda installation
  • Else, have a look at <env folder>/conda-meta/history file to look at the conda installation that was used to create this environment

for possible_conda_folder in get_known_conda_install_locations(environment) {
if possible_conda_folder.exists() {
if let Some(manager) = get_conda_manager(&possible_conda_folder) {
let envs = get_conda_environments_from_conda_directory(
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two are the key functions get_conda_manager and get_conda_environmetns_from_conda_directory
Given any conda installation, we can find all conda exes and all envs.
Thus we can easily support anaconda, miniconda, miniforge, even conda installs where the directory is found from the windows registry...

@DonJayamanne DonJayamanne added no-changelog No news entry required skip package*.json package.json and package-lock.json don't both need updating skip tests Updates to tests unnecessary labels May 13, 2024
@DonJayamanne DonJayamanne marked this pull request as ready for review May 13, 2024 13:00
@DonJayamanne DonJayamanne merged commit 614aae6 into native_locator May 13, 2024
64 checks passed
@DonJayamanne DonJayamanne deleted the revisedCondaLocator branch May 13, 2024 13:00
anthonykim1 pushed a commit to anthonykim1/vscode-python that referenced this pull request May 16, 2024
**Fixes**
* microsoft#23413
* & the fact that we always use the same conda exe to manage all conda
envs, even if multiple are installed.

* Step 1:
* Look for conda install folders in known locations such as `/<user
home>/miniconda3`, `<user profile>/Anaconda3`
* Step 2:
* For each install location identified, inspect that folder and extract
the
        * Conda executable
        * All environments belonging to that conda installation
* Step 3:
    * Old approach, 
* 1. find any conda in sys path or other locations and find conda
installation via that mechanism
* 2. Get all envs from environments.txt file (any remaining conda envs
not discovered in 1 & 2 will be discoverred here and use some the global
conda exe)
Once we have step 1 and 2, I do not expect anything new to show up in
step 3,
Even if users install conda into some custom locations (the solution
would be to run step 1 with the custom location provided by user in
settings.json file)

**How to find environments?**
* Look in the `envs` folder of the conda installation
* Look at the entries in the `environments.txt` file
* Look at the `env_dirs` in the `.condarc` file

With these two, we should be able to eliminate the need to ever spawn
conda to get the env directories.


**How do we know whether a conda environment belongs to a specific conda
installation**
* If it is in the `envs` sub directory of the conda installation
* Else, have a look at `<env folder>/conda-meta/history` file to look at
the conda installation that was used to create this environment
DonJayamanne added a commit that referenced this pull request Jun 24, 2024
**Fixes**
* #23413
* & the fact that we always use the same conda exe to manage all conda
envs, even if multiple are installed.

* Step 1:
* Look for conda install folders in known locations such as `/<user
home>/miniconda3`, `<user profile>/Anaconda3`
* Step 2:
* For each install location identified, inspect that folder and extract
the
        * Conda executable
        * All environments belonging to that conda installation
* Step 3:
    * Old approach, 
* 1. find any conda in sys path or other locations and find conda
installation via that mechanism
* 2. Get all envs from environments.txt file (any remaining conda envs
not discovered in 1 & 2 will be discoverred here and use some the global
conda exe)
Once we have step 1 and 2, I do not expect anything new to show up in
step 3,
Even if users install conda into some custom locations (the solution
would be to run step 1 with the custom location provided by user in
settings.json file)

**How to find environments?**
* Look in the `envs` folder of the conda installation
* Look at the entries in the `environments.txt` file
* Look at the `env_dirs` in the `.condarc` file

With these two, we should be able to eliminate the need to ever spawn
conda to get the env directories.


**How do we know whether a conda environment belongs to a specific conda
installation**
* If it is in the `envs` sub directory of the conda installation
* Else, have a look at `<env folder>/conda-meta/history` file to look at
the conda installation that was used to create this environment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-changelog No news entry required skip package*.json package.json and package-lock.json don't both need updating skip tests Updates to tests unnecessary
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant